<?php

namespace Caifenglei\AuthRbac\Http\Requests;

use Caifenglei\AuthRbac\Models\User;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

class CreateUserRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     */
    public function authorize(): bool
    {
        // TODO 权限管理
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
     */
    public function rules(): array
    {
        return [
            'identity_type' => [
                'required',
                'integer'
            ],
            'org_id' => 'sometimes|required|integer',
            'org_no' => 'required_with:org_id|string', //TODO 校验org id的正确性
            'user_name' => 'required|string|max:255',
            'user_pwd' => 'required|string|min:8', //TODO 密码复杂度: 大写小写字母加数字
            'role_ids' => 'required|array',
            'status' => [
                'required',
                'integer',
                Rule::in([User::STATUS_AVAILABLE, User::STATUS_FORBIDDEN])
            ],
            'name' => 'required|string|max:50', //姓名
            'cardno' => 'required|string|max:18', //TODO 身份证号验证
            'phone' => 'required|string|max:11',
            'sex' => [
                'required',
                'integer',
                Rule::in([User::GENDER_MALE, User::GENDER_FEMALE])
            ],
        ];
    }

    public function messages()
    {
        return parent::messages(); // TODO: Change the autogenerated stub
    }
}
